<?php
/**
 * Crud Padrao para noticias
 * @author Emanuel Melo @ PC4 Team em 13/03/2012
 *
 */
class PC4_Crud_NoticiasMuitosParaMuitos extends PC4_Crud_MuitosParaMuitos {
	
    function preparaConsulta($where = null, $order = null, $count = null, $offset = null) {
    	$select = parent::preparaConsulta($where, $order, $count, $offset);
    	$select->columns('GROUP_CONCAT(' . $this->getAlias($this->tabelaCategoria) . ' . ' . $this->pkCategoria . ') AS ' . $this->fk);
		$select->group($this->getAlias($this->_name) . '.' . $this->pk);
		return $select;
    }

	
	/* TODO: Verificar se ainda tera o esquema de criacao de tabela caso nao exista
	function criaTabela($e) {
		// Criando a tabela principal
		$sql = 
			"CREATE  TABLE IF NOT EXISTS `" . $this->_name . "` (
			  `" . $this->pk . "` INT NOT NULL AUTO_INCREMENT ,
			  `titulo` VARCHAR(255) NOT NULL ,
			  `imagem` VARCHAR(34) NULL ,
			  `texto` TEXT NOT NULL ,
			  `ativo` TINYINT(1) NOT NULL DEFAULT 1 ,
			  `registro` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
			  PRIMARY KEY (`" . $this->pk . "`) )
			ENGINE = InnoDB";
new d($sql);
		$db = $this->getAdapter();
		$db->query($sql);
		
		// Criando tabela de categoria
		$sql =
			"CREATE  TABLE IF NOT EXISTS `" . $this->tabelaCategoria . "` (
			  `" . $this->pkCategoria . "` INT NOT NULL AUTO_INCREMENT ,
			  `" . $this->nomeCategoria . "` VARCHAR(60) NOT NULL ,
			  `registro` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
			  PRIMARY KEY (`" . $this->pkCategoria . "`) )
			ENGINE = InnoDB";
new d($sql);
		$db->query($sql);
		
		// Criando tabela de relacionamento de categorias
		$sql =
			"CREATE  TABLE IF NOT EXISTS `" . $this->tabelaRel . "` (
			  `" . $this->fk . "` INT NOT NULL ,
			  `" . $this->fkCategoria . "` INT NOT NULL ,
			  PRIMARY KEY (`" . $this->fk . "`, `" . $this->fkCategoria . "`) ,
			  INDEX `" . $this->fk . "` (`" . $this->fk . "` ASC) ,
			  INDEX `" . $this->fkCategoria . "` (`" . $this->fkCategoria . "` ASC) ,
			  CONSTRAINT `" . $this->fk . "`
			    FOREIGN KEY (`" . $this->fk . "` )
			    REFERENCES `" . $this->_name . "` (`" . $this->pk . "` )
			    ON DELETE NO ACTION
			    ON UPDATE NO ACTION,
			  CONSTRAINT `" . $this->fkCategoria . "`
			    FOREIGN KEY (`" . $this->fkCategoria . "` )
			    REFERENCES `" . $this->tabelaCategoria . "` (`" . $this->pkCategoria . "` )
			    ON DELETE NO ACTION
			    ON UPDATE NO ACTION)
			ENGINE = InnoDB";
new d($sql); die;
		$db->query($sql);
	}
	*/
}